define(function(required, exports, modules) {
  var modal = require("mods/modal");

  exports.create = function() {
    $(".create_mediation").click(function() {
      if ($(this).hasClass("disabled")) {
        modal.alert("系统正在处理中,请不要重复请求");
        return false;
      }

      var admin_name = $("input[name=admin_name]").val();
      var admin_pwd = $("input[name=admin_pwd]").val();
      var _csrf = $("#csrf").val();
      var admin_id = $("input[name=admin_id]").val();

      if (admin_name.length < 2) {
        modal.msg("管理员名称不能小于2位");
        return false;
      }
      if (admin_pwd.length < 6) {
        modal.msg("用户密码不能小于6位");
        return false;
      }

      $(this).addClass("disabled");
      $.ajax({
        url: "/admin/permissions/create-mediation",
        type: "POST",
        dataType: "json",
        data: {
          admin_name: admin_name,
          admin_pwd: admin_pwd,
          admin_id: admin_id,
          _csrf: _csrf
        },
        success: function(res) {
          $(this).removeClass("disabled");
          if (res.code == 200) {
            modal.msg(res.msg, {}, function() {
              window.location.reload();
            });
          } else {
            modal.alert(res.msg);
            return false;
          }
        }
      });
    });
  };
});
